Expand description
Stretto is a pure Rust implementation for https://github.com/dgraph-io/ristretto.
A high performance thread-safe memory-bound Rust cache.
Structs§
- AsyncCache
async
AsyncCache is a thread-safe async implementation of a hashmap with a TinyLFU admission policy and a Sampled LFU eviction policy. You can use the same AsyncCache instance from as many threads as you want. - AsyncCacheBuilder
async
TheAsyncCacheBuilder
struct is used when creatingAsyncCache
instances if you want to customize theAsyncCache
settings. - Cache
sync
Cache is a thread-safe implementation of a hashmap with a TinyLFU admission policy and a Sampled LFU eviction policy. You can use the same Cache instance from as many threads as you want. - CacheBuilder
sync
- DefaultKeyBuilder is a built-in
KeyBuilder
for the Cache. Histogram
stores the information needed to represent the sizes of the keys and values as a histogram.- Item is the parameter when Cache reject, evict value,
- Dummy hasher will do nothing. Used by
TransparentKeyBuilder
. - TransparentKeyBuilder converts key to
u64
. If the key does not implement the traitTransparentKey
, please useDefaultKeyBuilder
or write a custom key builder. - ValueRef is returned when invoking
get
method of the Cache. It contains aRwLockReadGuard
and a value reference. - ValueRefMut is returned when invoking
get_mut
method of the Cache. It contains aRwLockWriteGuard
and a mutable value reference.
Enums§
- CacheError contains the error of this crate
- The data field in a Metrics
- Metrics is a snapshot of performance statistics for the lifetime of a cache instance.
Traits§
- CacheCallback is for customize some extra operations on values when related event happens.
- Cost is a trait you can pass to the CacheBuilder in order to evaluate item cost at runtime, and only for the
insert
calls that aren’t dropped (this is useful if calculating item cost is particularly expensive, and you don’t want to waste time on items that will be dropped anyways). KeyBuilder
is the hashing algorithm used for every key. In Stretto, the Cache will never store the real key. The key will be processed byKeyBuilder
. Stretto has two default built-in key builder, one isTransparentKeyBuilder
, the other isDefaultKeyBuilder
. If your key implementsTransparentKey
trait, you can useTransparentKeyBuilder
which is faster thanDefaultKeyBuilder
. Otherwise, you should useDefaultKeyBuilder
You can also write your own key builder for the Cache, by implementingKeyBuilder
trait.- Implement this trait for the key, if you want to use
TransparentKeyBuilder
as theKeyBuilder
for theCache
. - By default, the Cache will always update the value if the value already exists in the cache, this trait is for you to check if the value should be updated.